<template lang="html">
  <div class="sidebarMenu">
    <el-menu
      :default-active="activeSidebarMenu"
      class="el-menu-vertical-demo"
      :router="true"
      :unique-opened="true"
      :collapse="$store.state.isCollapse"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
      mode="vertical"
    >
      <menu-item
        v-for="route in routes"
        :key="route.path"
        :base-path="route.path"
        :route="route"
      />
    </el-menu>

    <!-- <el-menu
      default-active="1"
      class="el-menu-vertical-demo"
      :router="true"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
    >
      <el-menu-item index="1" :route="{ name: 'dashboard' }">
        <i class="el-icon-menu"></i>
        <span slot="title">首页</span>
      </el-menu-item>
      <el-submenu index="2">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>用户管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="2-1" :route="{ name: 'seestarList' }"
            >招募管理</el-menu-item
          >
          <el-menu-item index="2-2" :route="{ name: 'agentList' }"
            >运营管理</el-menu-item
          >
        </el-menu-item-group>
      </el-submenu>
      <el-submenu index="3">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>系统管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="3-1" :route="{ name: 'adminList' }"
            >账号管理</el-menu-item
          >
          <el-menu-item index="3-2" :route="{ name: 'organizationList' }"
            >架构管理</el-menu-item
          >
        </el-menu-item-group>
      </el-submenu>
    </el-menu> -->
  </div>
</template>

<script>
import menuItem from "./components/menuItem";

export default {
  name: "sidebar",
  components: { menuItem },
  data: () => ({}),
  created() {},
  computed: {
    routes() {
      // return this.$router.options.routes; // 只能静态，不能根据生成去显示
      return this.$store.state.routes;
    },
    activeSidebarMenu() {
      const route = this.$route;
      // console.log('activeSidebarMenu', route.path)
      // if set path, the sidebar will highlight the path you set
      // console.log("route.activeSidebarMenu", route);
      if (route.meta && route.meta.activeSidebarMenu) {
        return route.meta.activeSidebarMenu;
      }
      return route.path;
    }
  },
  methods: {
    rNavigateTo(route) {
      const { path } = route;
      this.$router.push(path);
    }
  }
};
</script>

<style lang="scss" scoped>
.sidebarMenu {
  .el-menu {
    border-right: none;
  }
}
</style>
